package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityFlashlightBinding;
import stark.common.basic.utils.StkFlashUtil;

public class FlashlightActivity extends BaseAc<ActivityFlashlightBinding> {

    private boolean isOpen;

    @Override
    protected int onCreate() {
        return R.layout.activity_flashlight;
    }

    @Override
    protected boolean isStatusBarTextDark() {
        return false;
    }

    @Override
    protected void initView() {
        mDataBinding.ivFlashlightBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivFlashlightSwitch.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivFlashlightSwitch://开启/关闭
                openFlash();
                break;
        }
    }

    @Override
    protected void initData() {
        StkFlashUtil.setFlashlightStatus(false);
    }

    //打开/关闭闪光灯
    private void openFlash() {
        if (isOpen) {
            isOpen = false;
            StkFlashUtil.setFlashlightStatus(false);
            mDataBinding.ivFlashlightSwitch.setImageResource(R.drawable.asdtg);
            mDataBinding.tvFlashlightSwitch.setText(getString(R.string.flashlight_is_close));
        } else {
            isOpen = true;
            StkFlashUtil.setFlashlightStatus(true);
            mDataBinding.ivFlashlightSwitch.setImageResource(R.drawable.asdtk);
            mDataBinding.tvFlashlightSwitch.setText(getString(R.string.flashlight_is_open));
        }
    }

}